package comm.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;

/**
 * <PRE>
 * Filename      : RequestManager.java
 * Class         : RequestManager.class
 * Comment       :
 * History       :  2009. 01. 09     박용재 
 * 					: 2009. 08 .05    김장현 ( UTF-8  & key값 upper)
 * </PRE>
 *
 * @version : 1.1
 */

public class RequestManager {
	
	final static private Logger logger = Logger.getLogger(RequestManager.class);

	
	public static SoptHashMap getRequest(HttpServletRequest request) throws UnsupportedEncodingException{
		request.setCharacterEncoding("UTF-8");
		SoptHashMap hashData = new SoptHashMap();
		
		String v_key   = "";
        String v_value = "";
        String arValue[];
        
        ArrayList alValue = null;
        Enumeration e = request.getParameterNames();
        
        while (e.hasMoreElements()) {
            v_key = (String)e.nextElement();
            arValue = request.getParameterValues(v_key);
            if(arValue != null && arValue.length == 1){
            	v_value = arValue[0];
            	//v_value = CommUtil.replaceQuoates(v_value,"'","/'");
            	v_value = URLDecoder.decode(v_value, "UTF-8");
                hashData.put(v_key.toUpperCase(), v_value);
                
            }else if(arValue != null && arValue.length > 1){
            	alValue = new ArrayList();
            	for(int i = 0; i < arValue.length; i++){
            		arValue[i] = v_value = URLDecoder.decode(arValue[i], "UTF-8");
            		alValue.add(arValue[i]);
            	}
            	hashData.put(v_key.toUpperCase(), alValue);
            	
            	
            }else{
            	hashData.put(v_key.toUpperCase(), null);
            }
        }
        return hashData;
	}
	
}
